package com.javaGame.role;

import com.javaGame.frame.MainFrame;

import java.awt.*;

/**
 * 所有角色的父类
 */
public abstract class BaseRole {
    /**角色的X坐标*/
    protected int x;
    /**角色的Y坐标*/
    protected int y;
    /**角色的宽度*/
    protected int width;
    /**角色的高度*/
    protected int height;
    /**角色当前应该绘制的图片*/
    protected Image currentImg;
    /**角色碰撞区域*/
    protected Rectangle rect = new Rectangle();

    public BaseRole(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    /**
     * 绘制当前角色
     * @param memaryGraphics 内存画笔
     */
    public void drawMySelf(Graphics memaryGraphics){
        memaryGraphics.drawImage(this.currentImg,
                x,y,width,height,null);
        this.setRect();
        this.move();
        this.removeThis();
    }

    /**
     * 设置角色碰撞区域
     */
    public void setRect(){
        rect.x = this.x + this.width/4;
        rect.y = this.y + this.height/4;
        rect.width = this.width/2;
        rect.height = this.height/2;
    }

    public abstract void move();

    /**
     * 角色超出屏幕，移除该角色
     */
    public void removeThis(){
        if(this.x > 1200 || this.x< -200 || this.y < -200
            || this.y > 900){
            MainFrame.roleList.remove(this);
        }
    }
}
